<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
);

/*得到根域名 为了设置 根cookie*/
$host = $_SERVER['HTTP_HOST'];
// var_dump($_SERVER['HTTP_COOKIE']);
$host = explode(':', $host)[0];
$hostArr = explode('.', $host);
$tmp = count($hostArr);
if( !is_numeric($hostArr[count($hostArr)-1]) ){//最后一组不是数字，说明不是ip
    if($tmp > 2){
        $len = 2;
        if(($hostArr[$tmp-2] . $hostArr[$tmp-1] == 'comcn')
            or ($hostArr[$tmp-2] . $hostArr[$tmp-1] == 'netcn')
            or ($hostArr[$tmp-2] . $hostArr[$tmp-1] == 'govcn')){
            $len = 3;
        }
        foreach($hostArr as $k => $v){
            if($k < $tmp-$len){
                unset($hostArr[$k]);
            }
        }
    }
    $domain = '.' . implode('.', $hostArr);
}else{
    $domain = implode('.', $hostArr);
}
// var_dump($domain);

return [
    'id' => 'app-ac',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'ac\controllers',
    'bootstrap' => ['log'],
    'modules' => [
        /*开发者*/
        'developer' => [
            'class' => 'ac\modules\developer\Developer',
        ],
        /*应用中心*/
        'appcenter' => [
            'class' => 'ac\modules\appcenter\Appcenter',
        ],
        /*会员中心*/
        'member' => [
            'class' => 'ac\modules\member\Member',
        ],
        /*账户中心*/
        'acount' => [
            'class' => 'ac\modules\acount\Acount',
        ],
        /*权限控制*/
        'control' => [
            'class' => 'ac\modules\control\Control',
        ],
        /*通用设置*/
        'general' => [
            'class' => 'ac\modules\general\General',
        ],
        /*我的经销商*/
        'company' => [
            'class' => 'ac\modules\company\Company',
        ],
        /*epi content*/
        'content' => [
            'class' => 'app\modules\content\Content',
        ],
        /*epi content*/
        'epi' => [
            'class' => 'app\modules\epi\Epi',
        ],
        /*epi api*/
        'api' => [
            'class' => 'app\modules\api\Api',
        ],
    ],
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-ac',
            'enableCsrfValidation' => false,//关闭CSRF认证
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-ac', 'httpOnly' => true],
        ],
        'session' => [
            // this is the name of the session cookie used for login on the ac
            'name' => 'session-ac',
            'class' => 'yii\redis\Session',
            'redis' =>'redis',
            'useCookies' => true,
            'keyPrefix' => 'ac.',
            'timeout' => 36000,//过期时间 亲测有效
            'cookieParams' => [
                'secure' => true,
                'httpOnly' => true,
                'path' => '/',
                // 'domain' => '.super.com',
                'domain' => $domain,
                'lifetime' => 36000,//过期时间 这个不起作用，也不知道是什么
                // 'SameSite' => 'none'
            ],
        ],
        'jwt' => [
            'class' => \sizeg\jwt\Jwt::class,
            'key'   => 'secret',
            'jwtValidationData' => [
                'class' => \sizeg\jwt\JwtValidationData::class,
                 // configure leeway 
                'leeway' => 20,
            ],
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            // 'errorAction' => 'public/error',
            'class' => 'ac\component\exception\ErrorHandler',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
        // 'db' => [
        //     'class' => 'yii\db\Connection',
        //     'dsn' => 'mysql:host=localhost;dbname=su_ac',
        //     'username' => 'root',
        //     'password' => '123456',
        //     'charset' => 'utf8',
        //     'tablePrefix' => 'su_ac_',   //前缀
        // ],
        // 'redis' => [
        //     'class' => 'yii\redis\Connection',
        //     'hostname' => 'localhost',
        //     'port' => 6379,
        //     'database' => 0,
        // ],
    ],
    'params' => $params,
];
